package com.zsck.zsgy.ui.main.fragment.home.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.youth.banner.adapter.BannerAdapter;
import com.zsck.zsgy.ui.main.bean.HomeBean;
import com.zsck.zsgy.util.Constants;
import com.zsck.zsgy.util.GlideUtils;

import java.util.List;

public class MyBannerAdapter extends BannerAdapter<HomeBean.BannerBean, MyBannerAdapter.BannerViewHolder> {

    private Context mContext;
    public MyBannerAdapter(List<HomeBean.BannerBean> datas,Context context) {
        super(datas);
        this.mContext=context;
    }

    @Override
    public BannerViewHolder onCreateHolder(ViewGroup parent, int viewType) {
        ImageView imageView = new ImageView(parent.getContext());
//        ScreenUtils.getAppScreenWidth()
        imageView.setLayoutParams(new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        return new BannerViewHolder(imageView);
    }

    @Override
    public void onBindView(BannerViewHolder holder, HomeBean.BannerBean data, int position, int size) {
        if(data.getContentCoverFile()!=null&&data.getContentCoverFile().getFileId()!=null){
            String imageUrl =Constants.Companion.getIMG_HOST() +data.getContentCoverFile().getFileId();
            GlideUtils.display(imageUrl, holder.imageView,mContext);
        }

    }

    class BannerViewHolder extends RecyclerView.ViewHolder {
        ImageView imageView;
        public BannerViewHolder(@NonNull ImageView view) {
            super(view);
            this.imageView = view;
        }
    }
}
